package com.an.framework.springtest.aware;

import java.io.IOException;
import java.nio.charset.Charset;

import javax.annotation.PostConstruct;

import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;

import com.an.framework.springtest.async.MyAsyncService;

/**
 * @author Administrator
 *
 */
@Service
public class AwareServiceTest implements BeanNameAware, ResourceLoaderAware {

	private String name;
	private ResourceLoader loader;
	
	@Autowired
	private MyAsyncService asyncService;

	public void setResourceLoader(ResourceLoader arg0) {
		this.loader = arg0;
	}

	public void setBeanName(String arg0) {
		this.name = arg0;
	}

	
	@PostConstruct
	public void test() {
		System.out.println("bean的名字" + name);
		Resource resource = loader.getResource("classpath:redis.properties");
		try {
			System.err.println("加载的文件的内容为： " + IOUtils.toString(resource.getInputStream(), Charset.forName("UTF-8")));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		for(int i = 0;i<15;i++) {
			asyncService.test(i + "");
			asyncService.test2(i + "");

		}
		
	}
}
